using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;

[CustomEditor(typeof(GoogleAdsManager))]
public class AdsEditor : Editor
{
    // Start is called before the first frame update
    public override void OnInspectorGUI()
    {
        var m_Target = (GoogleAdsManager)target;

        GUILayout.Space(3);
        EditorGUILayout.BeginVertical("Box");
        EditorGUILayout.BeginVertical("Toolbar"); //Fixed height
        EditorGUILayout.LabelField("Main Ads Admob", EditorStyles.boldLabel);
        EditorGUILayout.EndVertical();

        //m_Target.AndroidInterstitialID = EditorGUILayout.TextField("Interstital Id", m_Target.AndroidInterstitialID);
        //m_Target.AndroidBannerID = EditorGUILayout.TextField("Banner Id", m_Target.AndroidBannerID);
        GUILayout.Space(3);
        EditorGUILayout.EndVertical();

        GUILayout.Space(8);
        GUILayout.Space(3);
        EditorGUILayout.BeginVertical("Box");
        EditorGUILayout.BeginVertical("Toolbar"); //Fixed height
        EditorGUILayout.LabelField("Backup Ads StartApp", EditorStyles.boldLabel);
        EditorGUILayout.EndVertical();
        EditorGUI.BeginChangeCheck();
        //m_Target.startAppID = EditorGUILayout.TextField("App Id", m_Target.startAppID);
        if (EditorGUI.EndChangeCheck())
        {

            string path = Path.Combine(Application.dataPath, "Resources/StartAppDataAndroid.txt");
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            StringBuilder sb = new StringBuilder();
            //sb.AppendFormat("applicationId={0}", m_Target.startAppID).AppendLine();
            sb.AppendFormat("returnAds={0}", "false").AppendLine();
            File.WriteAllText(path, sb.ToString());

            AssetDatabase.Refresh();

            //Debug.Log("Changed");
            //     // Do something when the property changes 
        }

        GUILayout.Space(3);
        EditorGUILayout.EndVertical();

        GUILayout.Space(8);

        //m_Target.showAfterDie = EditorGUILayout.IntField("Show after die", m_Target.showAfterDie);
        EditorUtility.SetDirty(m_Target);

    }
}
